Put the Code back to the Main Queue π
Post
Replies
Boosts
Views
Activity
Hello Together,thanks, to think after about that problem.@OOPer: yep, this looks as the only solution for the long run. Kind regardsDWD
Hello Claude,so you see also no way to convert an Image to UIImage...The other way round, there is no problem, I knowKind RegardsDWD
Hello Claude,this was only for demonstration, not for work.but this not the solution, to change the data type from UIImage to Image, because I need it (datatype UIImage) for further procession in an UIKit View (datatype of struct WorkOnPicture).GreedsDWD
Hello Claude,so, I made an Example. The Error occures, wehn teh view "WorkOnPicture" with the Binding will be called. Only the struct ContentView should be modified...import SwiftUI
import Combine
class GetPicture: ObservableObject {//get picture from everywhere
static let shared: GetPicture = GetPicture()
let willChange = PassthroughSubject<Image?, Never>()
@Published var image: Image? = nil {
didSet {
if image != nil {
willChange.send(image)
}
}
}
func get() {
image = Image("ExamplePNG")
}
}
struct WorkOnPicture: View {
@Binding var image: UIImage
var body: some View {
Text("Hello Picture")
}
}
struct ContentView: View {
@State var image: Image? = nil
var body: some View {
VStack {
image?.resizable().frame(width: 100, height: 100)
.contextMenu {
Button(action: { self.workWithPicture() }) {
Text("Edit")
Image(systemName: "pencil")
}.disabled(image == nil)
}
}.onReceive(GetPicture.shared.$image) { image in
self.image = image
}
.onAppear() {
GetPicture().get()
}
}
func workWithPicture() {
WorkOnPicture(image: image) //<- here is the problem
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}Kind regardsDWD
Please format your code!
you give back differend views. try to wrap them up in AnyView( ... ) (is also called type erased wrapper πbe caution, it's performance intensehttps://developer.apple.com/documentation/swiftui/anyviewDWD
try an own view with initializalization initializer, an example can you find thereKind RegadsDWD
Take a look on this threadGreedsDWD
Take the Button insteed. You can also use the List with Navigation Links, but not on a ForEach loop.Kind regardsDWD
Is there now a solution known? I have still this problem.
Hello, Claude,Thank you very much. I see you made this whole thing a lot more flexible than I wanted. The second view is the detail view and is always the same for this species.My idea was to create a new element from a list (normal object) and then automatically go to the detail view instead of letting the user press a dummy entry.Your solution is simply ingenious.I will have a closer look at it in the next few hours.
you call the initializer also on the other views. omit them and pass it over from one to the other view.
Hello Claude,thanks for the confirmation. Let's hope that there will be a fix for this problem in the next version.Edit: Merci. I see that this is probably the automatic layout adjustment for the iPad, which is playing a trick here.Have a nice evening